<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../vue.js"></script>
    <link rel="stylesheet" href="../animate.css">
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        .list_box {
            width: 400px;
            min-height: 100px;
            box-sizing: border-box;
            border-radius: 10px;
            margin: 10px auto;
            box-shadow: 0px 0px 10px #666;
        }
        
        .list_tit,
        .list_cont li {
            display: flex;
            justify-content: space-between;
            width: 400px;
            box-sizing: border-box;
            list-style: none;
            text-align: center;
            height: 50px;
        }
        
        .list_cont span {
            display: block;
        }
        
        .list_tit>li,
        .list_cont span {
            height: 50px;
            width: 100px;
            line-height: 50px;
        }
        
        .list_cont {
            width: 400px;
            list-style: none;
        }
        
        .change {
            width: 200px;
            position: absolute;
            bottom: 100px;
            left: calc(50% - 100px);
            display: flex;
            justify-content: space-between;
        }
        
        .change button {
            width: 100px;
            height: 50px;
            cursor: pointer;
            border: none;
            margin: 2px;
            box-shadow: 0px 0px 10px #666;
            border-radius: 5px;
        }
        
        .change .active {
            background-color: red;
        }
        
        .shake-enter-active {
            animation: shake 2s;
        }
        
        .shake-leave-active {
            animation: shake 2s;
        }
    </style>
</head>

<body>
    <div class="app">
        <h1 style="text-align: center;">{{title}}</h1>
        <hr>
        <div v-if="false">
            <list :car="car"></list>
            <tab :car="car"></tab>
        </div>
        <div class="change">
            <button @click="changestaic(0)" :class="staic==0?'active':''">表格切换</button>
            <button @click="changestaic(1)" :class="staic==1?'active':''">列表切换</button>
        </div>

        <!-- <transition name="shake" mode="out-in"> -->
        <component :is="cname" :car="car"></component>
        <!-- </transition> -->

    </div>

    <template id="list">
        <div class="list_box">
            <ul class="list_tit">
                <li>序号</li>
                <li>名字</li>
                <li>年龄</li>
                <li>爱好</li>
            </ul>
            <ul class="list_cont">
                <li v-for="(item,index) in car" :key="index">
                    <span>{{index+1}}</span>
                    <span>{{item.name}}</span>
                    <span>{{item.age}}</span>
                    <span>{{item.hoppy}}</span>
                </li>
            </ul>
        </div>
    </template>

    <template id="tab">
        <div class="list_box">
            <table>
                <thead>
                    <tr>
                        <td>序号</td>
                        <td>名字</td>
                        <td>年龄</td>
                        <td>爱好</td>
                   </tr>
                </thead>
                <tbody>
                    <tr v-for="(item,index) in car" :key="index">
                        <td>{{index+1}}</td>
                        <td>{{item.name}}</td>
                        <td>{{item.age}}</td>
                        <td>{{item.hoppy}}</td>
                   </tr>
                </tbody>
            </table>
        </div>
    </template>
    <script>
        Vue.component("list", {
            template: "#list",
            props: ["car"]
        })

        Vue.component("tab", {
            template: "#tab",
            props: ["car"]
        })

        let car = [{
            name: "不吃鱼的猫",
            age: 18,
            hoppy: "fishing"
        }, {
            name: "二狗子",
            age: 18,
            hoppy: "耍手机"
        }, {
            name: "小高",
            age: 18,
            hoppy: "宅家"
        }, {
            name: "九号",
            age: 18,
            hoppy: "fishing"
        }]


        const vm = new Vue({
            data: {
                title: "组价切换",
                car,
                staic: 0,
                cname: "tab",
                arr: ["tab", "list"],
            },
            methods: {
                changestaic(index) {
                    this.staic = index;
                    this.cname = this.arr[index]
                }
            }
        }).$mount(".app")
    </script>
</body>

</html>